<?php

namespace App\HttpController\XApp\Qr\Admin;


use App\HttpController\ControllerAdmin;
use App\Model\t_wx_qr;
use App\Model\t_wx_reply;
use XWX\Common\H;

class QrList extends ControllerAdmin
{
    public function index()
    {
        $this->funcSetTitle('二维码列表');


        $compKw = $this->reqParam('compKw');


        $type = '';
        if ($this->funcGetX__config()->aconfig_type == "wxapp")
        {
            $type = "wxapp";
        }


        $query = $this->db()
            ->join(t_wx_reply::table(), 'wxqr_reply_id = reply_id', "INNER")
            ->where('wxqr_x_id', $this->funcGetX())
            ->where('wxqr_type', $type)
            ->orderBy('wxqr_create_date');

        if (H::funcStrHasAnyText($compKw))
        {
            $query->where('wxqr_name', "%{$compKw}%", 'LIKE');
        }

        $query_count = clone $query;

        $list = $query->get(t_wx_qr::table(), [$this->funcGetPageIndexXPage(), $this->funcGetPageSize()]);
        $count = $query_count->count(t_wx_qr::table());


        //二次加工
        $list_ = [];
        foreach ($list as $v)
        {
            $data = $v;

            $data['id'] = $v['wxqr_id'];

            $list_[] = $data;
        }


        $this->commonR()->setData("list", $list_);
        $this->commonR()->setData("count", $count);


        $this->funcWriteCommonR();
    }
}